package com.yuan.thead;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadLearn {


    public static class T1 extends Thread {
        @Override
        public void run() {
            System.out.println("my name is T1 thread ");
        }
    }

    public static class T2 implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 5; ++i) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("my name is T2 Runnable ");
            }
        }
    }

    //@Test
    public void te1() {
        new T1().start();
        new Thread(new T2()).start();
        System.out.println("这是主线程");
        new Thread(() -> System.out.println("123")).start();
        ExecutorService pool = Executors.newCachedThreadPool();
        pool.submit(new T1());
        pool.submit(new T2());

    }

    //join 后 会按照 线程的顺序执行
    public static void main(String[] args) throws InterruptedException {
        Thread tjoin1 = new Thread(new T2());
        System.out.println(tjoin1.getState().toString());
        tjoin1.start();
        tjoin1.join();
        T1 tjoin2 = new T1();
        tjoin2.start();
        tjoin2.join();
        System.out.println(tjoin1.getState().toString());

    }


    public void aa() {
        //this 指向的是当前对象 等同于 下面的方法

        synchronized (this) {

        }
    }

    public synchronized void aac() {

    }

    //静态方法锁定的是 当前对象.class
    public static synchronized void acac() {

    }


}
